<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class B_sub_sy extends CI_Controller {

	function __construct() {
        parent::__construct();	
		$this->load->model("master/master_th_ajaran"); 
		$this->load->model("master/master_j_pendidikan"); 
		$this->load->model("bagi/bagi_subsidi_syahriyah"); 		
		$this->load->model("bagi/bagi_non_syahriyah"); 		
	}
	
	function index()
	{
		$data['judul'] = "Pembagian Susbsidi Syahriyah";
		$data['list'] = $this->bagi_subsidi_syahriyah->read();
		$data['main_view']='bagi/subsidi_syahriyah/tahun';
		$this->load->view('index',$data);
	}

	function jenjang($id_m_th_ajaran)
	{
		$data['judul'] = "Pembagian Susbsidi Syahriyah";
		$data['list'] = $this->bagi_subsidi_syahriyah->jenjang($id_m_th_ajaran);
		$data['list_ta'] = $this->master_th_ajaran->detail($id_m_th_ajaran);
		$data['main_view']='bagi/subsidi_syahriyah/jenjang';
		$this->load->view('index',$data);
	}

	function bulan($id_m_j_pendidikan,$id_m_th_ajaran)
	{
		$data['judul'] = "Pembagian Susbsidi Syahriyah";
		$data['list'] = $this->bagi_subsidi_syahriyah->bulan($id_m_j_pendidikan,$id_m_th_ajaran);
		$data['list_jp'] = $this->master_j_pendidikan->detail($id_m_j_pendidikan);
		$data['list_ta'] = $this->master_th_ajaran->detail($id_m_th_ajaran);		
		$data['main_view']='bagi/subsidi_syahriyah/bulan';
		$this->load->view('index',$data);
	}

	function tholabah($id_a_bulan,$id_m_j_pendidikan,$id_m_th_ajaran)
	{
		$data['judul'] = "Pembagian Susbsidi Syahriyah";
		$data['list'] = $this->bagi_subsidi_syahriyah->tholabah($id_a_bulan,$id_m_j_pendidikan); // List tholabah yang telah diberi subsidi pada jenjang yang diminta
		$data['list_tag'] = $this->bagi_subsidi_syahriyah->detail_tag($id_a_bulan,$id_m_j_pendidikan,$id_m_th_ajaran); // Detail tagihan pada tahun ajaran, jenjang dan bulan yang diminta
		$data['main_view']='bagi/subsidi_syahriyah/tholabah';
		$this->load->view('index',$data);
	}

	function subsidi()
	{
		$data['id_m_j_pendidikan'] = $id_m_j_pendidikan = $this->input->post('id_m_j_pendidikan');
		$data['list'] = $this->bagi_subsidi_syahriyah->subsidi();		
		$this->load->view('bagi/subsidi_syahriyah/ajax_subsidi',$data);
	}

	function sisa_subsidi()
	{
		$id_a_subsidi = $this->input->post('id_a_subsidi');
		$id_m_j_pendidikan = $this->input->post('id_m_j_pendidikan');
		$data['list'] = $this->bagi_subsidi_syahriyah->sisa_subsidi($id_a_subsidi);
		$data['list_k']=$this->bagi_non_syahriyah->list_kelas(id_ta_aktif(),$id_m_j_pendidikan); // Ambil kelas pada tahun sekarang dan jenjang yang sama
		$this->load->view('bagi/subsidi_syahriyah/ajax_sisa_dan_kelas',$data);
	}

	function list_tholabah_modal()
	{
		$id_m_j_pendidikan = $this->input->post('id_m_j_pendidikan');		
		$id_m_kelas = $this->input->post('id_m_kelas');
		$id_a_bulan = $this->input->post('id_a_bulan');
		$data['id_a_subsidi'] = $this->input->post('id_a_subsidi');
		$data['id_a_bulan'] = $this->input->post('id_a_bulan');
		$data['besar_subsidi'] = $this->input->post('besar_subsidi');
		$data['id_m_j_pendidikan'] = $this->input->post('id_m_j_pendidikan');
		$data['list']=$this->bagi_subsidi_syahriyah->list_tholabah_modal($id_m_j_pendidikan,$id_m_kelas,$id_a_bulan); // List tholabah pada th ajaran dan jenjang sama yang tidak ada sebg penerima subsidi yang diminta
		$this->load->view('bagi/subsidi_syahriyah/ajax_list_tholabah',$data);
	}

	function save()
	{	
		$list_id_m_th_id_b_kelas	=	$this->input->post('id_m_tholabah_id_b_kelas');
		if(isset($list_id_m_th_id_b_kelas)){
			foreach($list_id_m_th_id_b_kelas as $id_m_th_id_b_kelas){
				$array_id 		= explode('#', $id_m_th_id_b_kelas);
				$id_m_tholabah 	= $array_id[0];
				$id_b_kelas 	= $array_id[1];
				$dataInsert = array(					
					'id_m_tholabah'=>$id_m_tholabah,
					'id_a_subsidi'=> $this->input->post('id_a_subsidi'),
					'id_a_bulan'=> $this->input->post('id_a_bulan'),
					'id_b_kelas'=> $id_b_kelas,
					'besar_subsidi'=> $this->input->post('besar_subsidi')
				);
			$this->bagi_subsidi_syahriyah->save($dataInsert);
			}
		}
	}

	function delete()
	{
		$id_b_sub_sy = $this->input->post('id_b_sub_sy');
		$this->bagi_subsidi_syahriyah->delete($id_b_sub_sy);
	}

	function refresh()
	{
		$id_a_bulan = $this->security->xss_clean($this->uri->segment(3));
		$id_m_j_pendidikan = $this->security->xss_clean($this->uri->segment(4));
		$id_m_th_ajaran = $this->security->xss_clean($this->uri->segment(5));
		$data['list'] = $this->bagi_subsidi_syahriyah->tholabah($id_a_bulan,$id_m_j_pendidikan); // List tholabah yang telah diberi subsidi pada jenjang dan bulan yang diminta 
		$data['list_tag'] = $this->bagi_subsidi_syahriyah->detail_tag($id_a_bulan,$id_m_j_pendidikan,$id_m_th_ajaran); // Detail tagihan pada tahun ajaran, jenjang dan bulan yang diminta
		$this->load->view('bagi/subsidi_syahriyah/refresh',$data);
	}

	function refresh_jml()
	{
		$id_a_bulan = $this->security->xss_clean($this->uri->segment(3));
		$id_m_j_pendidikan = $this->security->xss_clean($this->uri->segment(4));
		$data['list'] = $this->bagi_subsidi_syahriyah->tholabah($id_a_bulan,$id_m_j_pendidikan); // List tholabah yang telah diberi subsidi pada jenjang dan bulan yang diminta 
		$this->load->view('bagi/subsidi_syahriyah/refresh_jml',$data);
	}

}